{include file='public/head'}
<body>
<style type="text/css" media="screen">
header {
    color: black;
}
</style>
<div class="x-body" >
	<form id="form" class="layui-form">

		  <div class="layui-form-item">
		    <label class="layui-form-label">登陆账号</label>
		    <div class="layui-input-block">
		    <input type="text" id="username"  name="username" lay-verify="required|username" autocomplete="off" placeholder="请输入登陆账号" class="layui-input">
		    </div>
		  </div>

		<!--<div class="layui-form-item">
			<label class="layui-form-label">
				权限
			</label>
			<div class="layui-input-block">
				<select name="power" id='power' lay-verify="required">
					<option value="0">管理自己</option>
					<option value="1">管理所有管理员</option>
				</select>
			</div>
		</div>-->

		<div class="layui-form-item">
		    <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;码</label>
		    <div class="layui-input-block">
		    <input type="password" id="password"  name="password" lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
		    </div>
	  	</div>

	  	<div class="layui-form-item">
		    <label class="layui-form-label">确&nbsp;&nbsp;&nbsp;认</label>
		    <div class="layui-input-block">
		    	<input type="password"  id="check_password"  name="check_password" lay-verify="required|repass" placeholder="请输入确认密码" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
		<div class="layui-form-item">
			<label class="layui-form-label">状&nbsp;&nbsp;&nbsp;态</label>
			<div class="layui-input-block">
				<input type="radio" name="status" value="1" title="正常" checked>
				<input type="radio" name="status" value="0" title="禁用">
			</div>
			</div>
		<div class="layui-form-item">
		    <div class="layui-input-block">
				<button  class="layui-btn" lay-filter="add" lay-submit="">添加</button>
		    </div>
		</div>


	</form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
	layui.use(['form','layer'], function(){
		$ = layui.jquery;
		var form = layui.form
				,layer = layui.layer;

		//自定义验证规则
		form.verify({
			username: function(value){
				if(value.length < 5){
					return '登陆账号至少得5个字符';
				}
			}
			,pass: [/(.+){5,16}$/, '密码必须5到16位']
			,repass: function(value){
				if($('#password').val()!=value){
					return '两次密码不一致';
				}
			}
		});

		//监听提交
		form.on('submit(add)', function(data){
			console.log(data);
			var form = new FormData();
			var t = $('#form').serializeArray();
			$.each(t, function() {
				form.append(this.name,this.value);
			});
			$.ajax({
				url:"{:url('admin/Admin/addAdmin')}",
				type:"post",
				data:form,
				dataType: "json",
				processData:false,
				contentType:false,
				success:function(data){
					if(data.code == 1){
						layer.msg(data.msg,{icon: 1, time: 2000});
						setTimeout(function () {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //执行关闭
							parent.location.href = window.parent.location;//返回父级页面
						},2000)
					}else{
						layer.msg(data.msg,{icon: 2, time: 2000});
					}
				}
			});
			return false;
		});

	});

</script>
